package com.power.sifa.approve.controller;

import cn.hutool.core.lang.Assert;
import com.alibaba.excel.EasyExcel;
import com.plf.common.domain.ResponseDTO;
import com.power.sifa.approve.api.IProcessApprove;
import com.power.sifa.approve.service.ProcessApproveService;
import com.power.sifa.correction.listener.AutoEndCaseListener;
import com.power.sifa.correction.model.pojo.bo.AutoEndCaseBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@RestController
public class ProcessApproveController implements IProcessApprove {

    @Resource
    ProcessApproveService processApproveService;

    @Override
    public ResponseDTO passRecord(String applyid, String category) {
        try {
            ResponseDTO res = this.processApproveService.passRecord(applyid, category);
            return ResponseDTO.succData(res);
        } catch (Exception e) {
            log.error("根据流程分类标识, 执行业务操作类失败 ->  msg[{}]", e.getMessage());
            return ResponseDTO.wrap(500, "文件校验失败");
        }
    }


    /**
     * 自动办结接口
     * @param file
     * @return
     */
    @Override
    public ResponseDTO autoEndCase(MultipartFile file) {
        Assert.notNull(file, "file不能为空");
        try {
            EasyExcel.read(file.getInputStream(), AutoEndCaseBO.class, new AutoEndCaseListener(processApproveService)).sheet().doRead();
            return ResponseDTO.succ();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseDTO.wrap(Integer.valueOf(500), "自动办结异常");
        }
    }
}
